package com.xbongbong.saas.script.help;

import com.xbongbong.paas.domain.entity.PaasFormEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LimitChooseRangePoJo;
import com.xbongbong.paas.field.LinkedAttrPoJo;
import com.xbongbong.paas.field.NumericalLimitsPoJo;
import com.xbongbong.paas.field.RelyPoJo;
import com.xbongbong.paas.field.SerialNumberPoJo;
import com.xbongbong.paas.field.VisibleRulePoJo;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.saas.base.EnumBase;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.script.pojo.LinkProductInitFieldPoJo;
import com.xbongbong.saas.script.tempenum.DemoIconEnum;
import com.xbongbong.saas.script.tempenum.SerialNumberEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 字段解释初始化帮助类
 * @author kaka
 */
public class SaasInitExplainsHelper {

    private static final Logger LOG = LoggerFactory.getLogger(SaasInitExplainsHelper.class);


    private static final List<Integer> DISTRIBUTOR_BUSINESSTYPE = Arrays.asList(XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.REFUND.getCode(), XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode());

    /**
     * 这些业务，初始化字段为空数组
     */
    public static final List<Integer> EMPTY_EXPLAIN = Arrays.asList(
            // CRM
            XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), XbbRefTypeEnum.CONTACT.getCode(), XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(),
            XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), XbbRefTypeEnum.QUOTATION.getCode(), XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.REFUND.getCode(),
            XbbRefTypeEnum.WORKREPORT_DAILY.getCode(), XbbRefTypeEnum.WORKREPORT_WEEKLY.getCode(), XbbRefTypeEnum.WORKREPORT_MONTHLY.getCode(),
            // 联系人表单下项目决策信息
            XbbRefTypeEnum.PROJECT_DECISION_INFO.getCode(),
            // 进销存
            XbbRefTypeEnum.SUPPLIER.getCode(), XbbRefTypeEnum.SUPPLIER_CONTACT.getCode(), XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(), XbbRefTypeEnum.PURCHASE.getCode(),
            XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), XbbRefTypeEnum.BOM_BILL.getCode(), XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), XbbRefTypeEnum.ASSEMBLE.getCode(),
            XbbRefTypeEnum.INVENTORY.getCode(), XbbRefTypeEnum.TRANSFER.getCode(), XbbRefTypeEnum.STOCK_FLOW_BILL.getCode(),  XbbRefTypeEnum.STOCK_STANDING_BOOK.getCode(),
            XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(), XbbRefTypeEnum.REFUND_INSTOCK.getCode(), XbbRefTypeEnum.OTHER_INSTOCK.getCode(), XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode(),
            XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(), XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(),
            XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(), XbbRefTypeEnum.WAREHOUSE.getCode(),
            // 资金
            XbbRefTypeEnum.PAYMENT.getCode(), XbbRefTypeEnum.PAYMENT_SHEET.getCode(), XbbRefTypeEnum.PREPAYMENT_BALANCE.getCode(), XbbRefTypeEnum.PAY_PLAN.getCode(), XbbRefTypeEnum.PAY_SHEET.getCode(),
            XbbRefTypeEnum.PREPAY_BALANCE.getCode(),  XbbRefTypeEnum.INVOICE.getCode(),  XbbRefTypeEnum.PURCHASE_INVOICE.getCode(),
            XbbRefTypeEnum.PAYMENT_TASK.getCode(),
            XbbRefTypeEnum.ONLINE_PAYMENT_FLOW.getCode(),
            XbbRefTypeEnum.CUSTOMER_STATEMENT.getCode(),
            XbbRefTypeEnum.CUSTOMER_STATEMENT_STATISTIC.getCode(),
            // 信用管理
            XbbRefTypeEnum.CREDIT_LIMIT.getCode(), XbbRefTypeEnum.CREDIT_FIXED_LIMIT.getCode(), XbbRefTypeEnum.CREDIT_TEMPORARY_LIMIT.getCode(), XbbRefTypeEnum.CREDIT_CARD_BILL.getCode(),
            // 其他收入、其他支出、资金调拨
            XbbRefTypeEnum.OTHER_INCOME.getCode(), XbbRefTypeEnum.OTHER_EXPENSE.getCode(), XbbRefTypeEnum.FUND_TRANSFER.getCode(),
            // 产品
            XbbRefTypeEnum.PRODUCT.getCode(),
            // 库存产品
            XbbRefTypeEnum.STOCK_PRODUCT.getCode(),
            // 工单
            XbbRefTypeEnum.WORK_ORDER.getCode(),
            // 批次流水
            XbbRefTypeEnum.BATCH_FLOW_BILL.getCode(),
            // 序列号流水
            XbbRefTypeEnum.SEQ_SEARCH.getCode(),
            // 市场管理
            XbbRefTypeEnum.MARKET_ACTIVITY.getCode(), XbbRefTypeEnum.CLUE.getCode(),
            // 营销管理
            XbbRefTypeEnum.MARKETING_MANAGEMENT.getCode(),
            XbbRefTypeEnum.MARKETING_TOOL.getCode(),
            XbbRefTypeEnum.MARKETING_ACTIVITY_MANAGEMENT.getCode(),
            XbbRefTypeEnum.MARKETING_ACTIVITY.getCode(),
            XbbRefTypeEnum.PROMOTION_TOOL.getCode(),
            XbbRefTypeEnum.PROMOTION_ACTIVITY_MANAGEMENT.getCode(),
            XbbRefTypeEnum.PROMOTION_ACTIVITY.getCode(),
            // 新工单
            XbbRefTypeEnum.WORK_ORDER_V2_APPOINT.getCode()
    );

    public static void setEmpty(FieldAttrEntity fieldAttrEntity) {
        setEmptyItem(fieldAttrEntity);
        setDateTypeNull(fieldAttrEntity);
        SetNumLimitNull(fieldAttrEntity);

    }
    public static void setEmptyItem(FieldAttrEntity fieldAttrEntity) {
        if (!ExplainUtil.isCombo(fieldAttrEntity.getFieldType())) {
            fieldAttrEntity.setItems(new ArrayList<>());
        }
    }

    public static void setDateTypeNull(FieldAttrEntity fieldAttrEntity) {
        if (!Objects.equals(FieldTypeEnum.DATETIME.getType(), fieldAttrEntity.getFieldType())) {
            fieldAttrEntity.setDateType(null);
        }
    }
    public static void SetNumLimitNull(FieldAttrEntity fieldAttrEntity) {
        // 非数字类型，不需要限制数据限制
        if (!Objects.equals(FieldTypeEnum.NUM.getType(), fieldAttrEntity.getFieldType())) {
            fieldAttrEntity.setNumericalLimits(null);
        }
    }

    /**
     *
     * @return new一个最基本的字段
     */
    public static FieldAttrEntity getNewFieldAttrEntity() {
        FieldAttrEntity fieldAttrEntity = new FieldAttrEntity();
        fieldAttrEntity.setMemo("");
        List<ItemPoJo> itemPoJoList = new ArrayList<>();
        ItemPoJo itemPoJo1 = new ItemPoJo();

        itemPoJo1.setText("选项值1");
        itemPoJo1.setValue("选项值1");
        itemPoJo1.setChecked(false);
        ItemPoJo itemPoJo2 = new ItemPoJo();
        itemPoJo2.setText("选项值2");
        itemPoJo2.setValue("选项值2");
        itemPoJo2.setChecked(false);
        ItemPoJo itemPoJo3 = new ItemPoJo();
        itemPoJo3.setText("选项值3");
        itemPoJo3.setValue("选项值3");
        itemPoJo3.setChecked(false);
        itemPoJoList.add(itemPoJo1);
        itemPoJoList.add(itemPoJo2);
        itemPoJoList.add(itemPoJo3);
        fieldAttrEntity.setItems(itemPoJoList);
        fieldAttrEntity.setVisible(1);
        fieldAttrEntity.setNoRepeat(0);
        fieldAttrEntity.setRequired(0);
        fieldAttrEntity.setOnlyCamera(0);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        RelyPoJo relyPoJo = new RelyPoJo();
        relyPoJo.setLinkField("");
        relyPoJo.setTargetField("");
        relyPoJo.setDisplayField("");
        defaultAttrPoJo.setRely(relyPoJo);
        defaultAttrPoJo.setDefaultType(null);
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIntegerOnly(0);
        fieldAttrEntity.setIsRedundant(0);
        fieldAttrEntity.setOnlyOneFile(0);
        fieldAttrEntity.setAutoCompress(0);
        fieldAttrEntity.setMaxFileCount(9);
        VisibleRulePoJo visibleRulePoJo = new VisibleRulePoJo();
        fieldAttrEntity.setVisibleScopeRule(visibleRulePoJo);
        fieldAttrEntity.setShowDetailAddress(1);
        fieldAttrEntity.setVisibleScopeEnable(0);
        fieldAttrEntity.setNumericalLimitsFlag(0);
        fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
        fieldAttrEntity.setComboType(0);
        fieldAttrEntity.setEditable(1);
        // saas系统系统字段精度默认两位，和以前保持一致
        fieldAttrEntity.setAccuracy(2);
        fieldAttrEntity.setLineType("dashed");
        return fieldAttrEntity;
    }


    /**
     * 设置字段名称等
     *
     * @param enumBase  封装了saas业务枚举的实体
     * @param enumAttrs  业务枚举类中的属性
     * @return  封装好属性的FieldAttrEntity实体
     * @author chaoxiong.lei
     * @Date 10:12 2019/1/16
     * @since  v1.0
     */
    public static FieldAttrEntity setField(EnumBase enumBase, List<String> enumAttrs) {
        if (enumBase == null || enumAttrs == null) {
            return null;
        }
        Class<?> clazz = enumBase.t.getClass();
        // 构造返回对象
        FieldAttrEntity fieldAttrEntity = getNewFieldAttrEntity();

        for (String fieldAttr : enumAttrs) {
            // "attr"转变成"Attr"，首字母大写
            String attr = fieldAttr.substring(0, 1).toUpperCase() + fieldAttr.substring(1);
            try {
                Method method = clazz.getMethod("get" + attr);
                Object value = method.invoke(enumBase.t);
                Type returnType = method.getGenericReturnType();

                Method setMethod = FieldAttrEntity.class.getMethod("set" + attr, Class.forName(returnType.getTypeName()));

                setMethod.invoke(fieldAttrEntity, value);
                if (Objects.equals("fieldType",fieldAttr)) {
                    Integer fieldType = Integer.parseInt(value.toString());
                    setEmpty(fieldAttrEntity);
                    String esAlias = FieldTypeEnum.getFieldTypeEnum(fieldType).getEsalias();
                    Method setAttrTypeMethod = FieldAttrEntity.class.getMethod("setAttrType", String.class);
                    setAttrTypeMethod.invoke(fieldAttrEntity, esAlias);
                }else if (Objects.equals("attrName",fieldAttr)){
                    Method method1 = FieldAttrEntity.class.getMethod("setDefaultName", String.class);
                    method1.invoke(fieldAttrEntity,value.toString());
                }
            } catch (NoSuchMethodException e) {
                // 可能情况：1.业务枚举中没有对应的方法，比如在业务枚举中新写了一个方法initName，那么就没有getInitName方法，这种情况直接continue
                // 2.FieldAttrEntity没有对应属性的set方法，（默认枚举和实体属性强一致的情况下）则证明业务枚举中的属性比字段实体中的属性多
                continue;
            } catch (Exception e) {
                // TODO lcx
                LOG.error(e.getMessage());
            }
        }
        return fieldAttrEntity;
    }

    /**
     * 设置字段名称等
     *
     * @param clazz  封装了saas业务枚举的实体
     * @param enumAttrs  业务枚举类中的属性
     * @return  封装好属性的FieldAttrEntity实体
     * @author chaoxiong.lei
     * @Date 10:12 2019/1/16
     * @since  v1.0
     */
    public static FieldAttrEntity setField(Class<?> clazz, List<String> enumAttrs,Object obj) {
        // 构造返回对象
        FieldAttrEntity fieldAttrEntity = getNewFieldAttrEntity();

        for (String fieldAttr : enumAttrs) {
            // "attr"转变成"Attr"，首字母大写
            String attr = fieldAttr.substring(0, 1).toUpperCase() + fieldAttr.substring(1);
            try {
                Method method = clazz.getMethod("get" + attr);
                Object value = method.invoke(obj);
                Type returnType = method.getGenericReturnType();

                Method setMethod = FieldAttrEntity.class.getMethod("set" + attr, Class.forName(returnType.getTypeName()));

                setMethod.invoke(fieldAttrEntity, value);
                if (Objects.equals("fieldType",fieldAttr)) {
                    Integer fieldType = Integer.parseInt(value.toString());
                    String esAlias = FieldTypeEnum.getFieldTypeEnum(fieldType).getEsalias();
                    Method setAttrTypeMethod = FieldAttrEntity.class.getMethod("setAttrType", String.class);
                    setAttrTypeMethod.invoke(fieldAttrEntity, esAlias);
                } else if (Objects.equals("attrName",fieldAttr)){
                    Method method1 = FieldAttrEntity.class.getMethod("setDefaultName", String.class);
                    method1.invoke(fieldAttrEntity,value.toString());
                }
            } catch (NoSuchMethodException e) {
                // 可能情况：1.业务枚举中没有对应的方法，比如在业务枚举中新写了一个方法initName，那么就没有getInitName方法，这种情况直接continue
                // 2.FieldAttrEntity没有对应属性的set方法，（默认枚举和实体属性强一致的情况下）则证明业务枚举中的属性比字段实体中的属性多
                continue;
            } catch (Exception e) {
                e.printStackTrace();
                // TODO lcx
                LOG.error("字段生成报错fieldAttr:-"+fieldAttr+",attr:-"+attr, e);
            }
        }
        return fieldAttrEntity;
    }

    /**
     * 获取业务枚举类中的属性，以集合的形式返回
     *
     * @param clazz 业务枚举类的class
     * @author chaoxiong.lei
     * @Date 10:13 2019/1/16
     * @since v1.0
     * @return 业务枚举类中的属性的集合
     */
    public static List<String> getBusinessEnumAttrs(Class<?> clazz) {
        // 获取全部的属性，包括属性(attr)、枚举(NAME)和默认方法($VALUES)
        Field[] declaredFields = clazz.getDeclaredFields();
        List<String> declaredFieldsList = new ArrayList<>();
        for (Field field : declaredFields) {
            declaredFieldsList.add(field.getName());
        }
        // 获取可见的属性，放入fieldsList中
        Field[] fields = clazz.getFields();
        List<String> fieldsList = new ArrayList<>();
        // clazz.getFields();方法不会获取到默认方法($VALUES)，所以这里手动加上
        fieldsList.add("$VALUES");
        for (Field field : fields) {
            fieldsList.add(field.getName());
        }
        // 两个list取差集获取到需要的属性值
        declaredFieldsList.removeAll(fieldsList);
        return declaredFieldsList;
    }
    /**
     *  设置字段名称等
     * @return
     */
    public static FieldAttrEntity setField(String attr,String alias,String saasAttr,Integer fieldType,Integer setType,Integer showType,Integer editHide,Integer edittable) {
        FieldAttrEntity fieldAttrEntity = getNewFieldAttrEntity();
        fieldAttrEntity.setAttr(attr);
        fieldAttrEntity.setAttrName(alias);
        fieldAttrEntity.setSaasAttr(saasAttr);
        fieldAttrEntity.setFieldType(fieldType);
        fieldAttrEntity.setSetType(setType);
        fieldAttrEntity.setShowType(showType);
        fieldAttrEntity.setEditHide(editHide);
        fieldAttrEntity.setEditable(edittable);
        fieldAttrEntity.setIcon(DemoIconEnum.getIconStr(fieldType));
        fieldAttrEntity.setIsRedundant(0);
        fieldAttrEntity.setAttrType(FieldTypeEnum.getFieldTypeEnum(fieldType).getEsalias());
        return fieldAttrEntity;
    }

    public static FieldAttrEntity setField(Enum anEnum, Integer type){
        return getNewFieldAttrEntity();
    }

    public static List<ItemPoJo> setCombItem(String str){
        List<ItemPoJo> itemPoJoList = new ArrayList<>();
        List<String> stringList = StringUtil.toStringList(str,",");
        Integer value = 1;
        for (String text : stringList){
            ItemPoJo itemPoJo = new ItemPoJo();
            itemPoJo.setText(text);
            itemPoJo.setValue(value.toString());
            itemPoJo.setChecked(false);
//            if (value == 0) {
//                itemPoJo.setChecked(true);
//            }
            itemPoJoList.add(itemPoJo);
            value++;
        }
        return itemPoJoList;
    }

    /**
     * 慎用
     * @param str
     * @return
     */
    public static List<ItemPoJo> setCombItemNumCode(String str){
        List<ItemPoJo> itemPoJoList = new ArrayList<>();
        List<String> stringList = StringUtil.toStringList(str,",");
        Integer value = 1;
        for (String text : stringList){
            ItemPoJo itemPoJo = new ItemPoJo();
            itemPoJo.setText(text);
            itemPoJo.setValue(value);
            itemPoJo.setChecked(false);
            if (value == 1) {
                itemPoJo.setChecked(true);
            }
            itemPoJoList.add(itemPoJo);
            value++;
        }
        return itemPoJoList;
    }


    /**
     * 设置下拉框的下拉选项
     *
     * @param itemsMap <key,value>的map
     * @author chaoxiong.lei
     * @Date 21:37 2019/1/17
     * @since v1.0
     **/
    public static List<ItemPoJo> setCombItem(Map<Integer, String> itemsMap) {
        List<ItemPoJo> itemPoJoList = new ArrayList<>();

        for (Map.Entry<Integer, String> entity : itemsMap.entrySet()){
            ItemPoJo itemPoJo = new ItemPoJo();
            itemPoJo.setText(entity.getValue());
            itemPoJo.setValue(entity.getKey().toString());
            itemPoJo.setChecked(false);
            itemPoJoList.add(itemPoJo);
        }
        return itemPoJoList;
    }

    /**
     * 设置下拉框的下拉选项
     *
     * @param itemsMap <key,value>的map
     * @author chaoxiong.lei
     * @Date 21:37 2019/1/17
     * @since v1.0
     **/
    public static List<ItemPoJo> setCombItemByStringMap(Map<String, String> itemsMap) {
        List<ItemPoJo> itemPoJoList = new ArrayList<>();

        for (Map.Entry<String, String> entity : itemsMap.entrySet()){
            ItemPoJo itemPoJo = new ItemPoJo();
            itemPoJo.setText(entity.getValue());
            itemPoJo.setValue(entity.getKey().toString());
            itemPoJo.setChecked(false);
            itemPoJoList.add(itemPoJo);
        }
        return itemPoJoList;
    }

    /**
     *
     * 流水号赋值
     * @param serialNumberEnum 流水号枚举
     * @return SerialNumberPoJo 流水号赋值实体
     * @author feng.zheng
     * @date 2019/1/18
     */
    public static SerialNumberPoJo setSerialNumber(SerialNumberEnum serialNumberEnum){
        SerialNumberPoJo serialNumberPoJo = new SerialNumberPoJo();
        serialNumberPoJo.setPrefix(serialNumberEnum.getPrefix());
        serialNumberPoJo.setPostfix(serialNumberEnum.getPostfix());
        serialNumberPoJo.setStartNum(serialNumberEnum.getStartNum());
        serialNumberPoJo.setDateFormat(serialNumberEnum.getDateFormat());
        serialNumberPoJo.setNumberDigit(serialNumberEnum.getNumberDigit());
        return serialNumberPoJo;
    }


    public static <T> List<ItemPoJo> setCombItemByEnum(Class<T> clazz,Integer fieldType,String textAlias,String valueAlias) {
        List<ItemPoJo> itemPoJoList = new ArrayList<>();
        Object[] objs = clazz.getEnumConstants();
        for (Object obj : objs) {
            try {
                String getText = Objects.isNull(textAlias) ? "getName" : "get" + textAlias.substring(0,1).toUpperCase() + textAlias.substring(1);
                String getValue = Objects.isNull(valueAlias) ? "getCode" : "get" + valueAlias.substring(0,1).toUpperCase() + valueAlias.substring(1);
                Object text = clazz.getMethod(getText).invoke(obj);
                Object value = clazz.getMethod(getValue).invoke(obj);
                if (Objects.equals(value,"404") || Objects.equals(value,404)){
                    continue;
                }
                ItemPoJo itemPoJo = new ItemPoJo();
                itemPoJo.setText(text.toString());
                if (Objects.equals(fieldType,FieldTypeEnum.COMBO.getType()) || Objects.equals(fieldType, FieldTypeEnum.RADIO_GROUP.getType()) || Objects.equals(fieldType, FieldTypeEnum.CHECKBOX_GROUP.getType())){
                    itemPoJo.setValue(value.toString());
                }else {
                    itemPoJo.setValue(Integer.valueOf(value.toString()));
                }
                itemPoJo.setChecked(false);
                itemPoJoList.add(itemPoJo);
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                e.printStackTrace();
            }
        }
        return itemPoJoList;
    }

    public static <T> List<ItemPoJo> setCombItemByEnum(Class<T> clazz, Integer fieldType) {
        return setCombItemByEnum(clazz,fieldType,null,null);
    }

    public void beforeSave(){
        //TODO 免费版判断超过1000数据
        //TODO 数据字典校验
        //TODO 关联联系人校验
        //TODO 生日校验
    }





    private static void setWorkOrderSelectProductField(FieldAttrEntity fieldAttrEntity, String alias, PaasFormEntity productForm) {
    }

    public static void commonFiledInit(FieldAttrEntity fieldAttrEntity) {
        Integer fieldType = fieldAttrEntity.getFieldType();
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
        if (Objects.isNull(fieldTypeEnum)){
            return;
        }
        switch (fieldTypeEnum){
            case NUM:
                fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
                break;
            case OWNERID:
            case COUSERID:
            case USER:
            case USER_GROUP:
                fieldAttrEntity.getDefaultAttr().setDefaultList(new ArrayList<>());
                break;
            case DEPT:
            case DEPT_GROUP:
                fieldAttrEntity.getDefaultAttr().setDefaultList(new ArrayList<>());
                fieldAttrEntity.setLimitChooseRange(new LimitChooseRangePoJo());
                break;
        }
    }


    protected static LinkProductInitFieldPoJo getLinkProductField(XbbRefTypeEnum xbbRefTypeEnum, FieldAttrEntity entity) {
        return new LinkProductInitFieldPoJo();

    }

    public static void setSelectWorkOrderProductField(FieldAttrEntity entity, PaasFormEntityExt productForm) {

    }

    protected static List<LinkedAttrPoJo> getLinkedAttr(XbbRefTypeEnum xbbRefTypeEnum) {
        // 由子类实现
        return new ArrayList<>();
    }


    private static List<LinkedAttrPoJo> getLinkedShowAttr(XbbRefTypeEnum xbbRefTypeEnum) {
        // 由子类实现
        return new ArrayList<>();
    }


    /**
     * 修改字段属性值,，用于国际化脚本
     * @param alias
     * @param fieldList
     */
    public static void updateFieldAttrEntity(String alias, List<FieldAttrEntity> fieldList) {
        try {
            // 拼装枚举类
            String aliasEnum = "Temp" + alias.substring(0, 1).toUpperCase() + alias.substring(1, alias.length()) + "Enum";
            // 拼装包名
            String className = "com.xbongbong.saas.script.tempenum." + aliasEnum;
            // 根据包名拿到对象
            Class clazz = Class.forName(className);
            // 获取getAllEnum方法
            Method method = clazz.getMethod("getAllEnum");
            List<Object> list = (List<Object>) method.invoke(clazz);
            List<String> enumAttrs = null;
            for (Object object : list) {
                // 根据方法getAnEnum拿到对应的枚举类
                Method nameMethod = object.getClass().getMethod("getAnEnum");
                Object anEnum = nameMethod.invoke(object);
                // 包装业务枚举类
                EnumBase<Object> enumBase = new EnumBase<>(anEnum);
                Class<?> enumBaseClazz = enumBase.t.getClass();
                if (enumAttrs == null) {
                    // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                    enumAttrs = getBusinessEnumAttrs(enumBaseClazz);
                }
                for (FieldAttrEntity fieldAttrEntity : fieldList) {
                    Method method0 = enumBaseClazz.getMethod("getAttr");
                    Object value0 = method0.invoke(enumBase.t);
                    if (Objects.equals(value0.toString(), fieldAttrEntity.getAttr())) {
                        Method method1 = enumBaseClazz.getMethod("getAttrName");
                        Object value1 = method1.invoke(enumBase.t);
                        Method method2 = FieldAttrEntity.class.getMethod("setAttrNameEn", String.class);
                        method2.invoke(fieldAttrEntity,value1.toString());
                    }
                }

            }

        } catch (Exception e) {
            e.printStackTrace();
            LOG.error(alias + "赋值出错");
        }

    }

}
